package com.linux.huhx.firstdemo2;

import com.linux.huhx.firstdemo.MailMessage;
import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * @Author: huhx
 * @Date: 2017-11-03 上午 11:38
 */
public class HuhxProducer {
    public static void main(String[] args) throws JMSException {
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
        Connection connection = connectionFactory.createConnection();
        connection.start();

        Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE); // 会话
        Topic destination = session.createTopic("LinuxSend");

        /* 生产者 */
        MessageProducer messageProducer = session.createProducer(destination);
        messageProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

        /* 发送消息 */
        MailMessage mailMessage = new MailMessage("huhx", "linux", "Welcome to ActiveMQ!");
        ObjectMessage message = session.createObjectMessage(mailMessage);
        messageProducer.send(message);
        session.commit();
        System.out.println("senting...");
    }
}
